home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / emul / cp4 / c2p_src / c2p_windowamiga.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  18KB  |  655 lines

  1. /* :ts=4                            c2p_windowamiga.c
  2.  *
  3.  *    cp4 - Commodore C+4 emulator
  4.  *    Copyright (C) 1998 Gáti Gergely
  5.  *
  6.  *    This program is free software; you can redistribute it and/or modify
  7.  *    it under the terms of the GNU General Public License as published by
  8.  *    the Free Software Foundation; either version 2 of the License, or
  9.  *    (at your option) any later version.
  10.  *
  11.  *    This program is distributed in the hope that it will be useful,
  12.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *    GNU General Public License for more details.
  15.  *
  16.  *    You should have received a copy of the GNU General Public License
  17.  *    along with this program; if not, write to the Free Software Foundation,
  18.  *    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19.  *
  20.  *    e-mail: gatig@dragon.klte.hu
  21.  */
  22. #include <proto/graphics.h>
  23. #include <exec/types.h>
  24. #include <graphics/gfxbase.h>
  25. #include <proto/exec.h>
  26. #include <exec/alerts.h>
  27. #include <proto/intuition.h>
  28. #include <proto/gadtools.h>
  29. #include <intuition/pointerclass.h>
  30. #include <proto/layers.h>
  31.  
  32. #include "cp4_ver.h"
  33.  
  34. #define C2P_VERSION        "1"
  35. #define C2P_REVISION    "3"
  36. #define C2P_AUTHOR        "Zavacki-gega"
  37. #define C2P_NAME        "WindowAmiga"
  38. #define C2P_DATE        DATE
  39. #define C2P_LOCALIZE
  40.  
  41. #include "c2p_module.c"
  42. #include "c2p_windowcard_palette.c"
  43. #include "c2p_color_priority.c"
  44.  
  45. extern void REGARGS c2pfull(    REG(a0,void *chunkyaddr),
  46.                                 REG(a1,void *planaraddr),
  47.                                 REG(d0,int bmx) );
  48. extern void REGARGS c2pdelta(    REG(a0,void *chunkyaddr),
  49.                                 REG(a1,void *deltaaddr),
  50.                                 REG(a2,void *planaraddr),
  51.                                 REG(a3,void *lineskip),
  52.                                 REG(d0,int bmx) );
  53. extern int REGARGS c2pinit(    REG(d0,int planewidth),
  54.                             REG(a0,unsigned char *linedeltavec),
  55.                             REG(d1,int planes) );
  56.  
  57. #define MSG_PROJECT            0
  58. #define MSG_RESET            1
  59. #define MSG_HARDRESET        2
  60. #define MSG_DEBUG            3
  61. #define MSG_PREFS            4
  62. #define MSG_QUIT            5
  63. #define MSG_OPTIONS            6
  64. #define MSG_JUMPSCR            7
  65. #define MSG_INFO            8
  66. #define MSG_ERRVISUALINFO    9
  67. #define MSG_ERRCREATEMENU    10
  68. #define MSG_ERROPENWIN        11
  69. #define MSG_ERRBITMAPATTR    12
  70. #define MSG_ERRBITPNUM        13
  71. #define MSG_ERRFINDCOLMAP    14
  72. #define MSG_ERROBTPENS        15
  73. #define MSG_ERRGRAPHICS        16
  74. #define MSG_ERRINTUITION    17
  75. #define MSG_ERRLAYERS        18
  76. #define MSG_ERRGADTOOLS        19
  77. #define MSG_ERRPOINTER        20
  78. #define MSG_RESET_A            21
  79. #define MSG_HARDRESET_A        22
  80. #define MSG_DEBUG_A            23
  81. #define MSG_PREFS_A            24
  82. #define MSG_QUIT_A            25
  83. #define MSG_JUMPSCR_A        26
  84.  
  85. static char *cp4_windowamiga_DefaultStrings[]={
  86.     "Project",
  87.     "Reset",
  88.     "HardReset",
  89.     "Debug...",
  90.     "Prefs...",
  91.     "Quit",
  92.     "Options",
  93.     "Jump PubScreen",
  94.     "Workbench window driver, works on AGA, ECS & OCS.",
  95.     "Can't find VisualInfo",
  96.     "Can't Create Menu",
  97.     "Can't open Window",
  98.     "Wrong BitMap Attributes",
  99.     "Wrong BitPlane Number",
  100.     "Can't Find ColorMap",
  101.     "Can't Obtain Pens",
  102.     "Can't open graphics.library V39",
  103.     "Can't open intuition.library V39",
  104.     "Can't open layers.library V33",
  105.     "Can't open gadtools.library V37",
  106.     "Can't Create Pointer",
  107.     "R",
  108.     "H",
  109.     "D",
  110.     "P",
  111.     "X",
  112.     "J",
  113.     NULL
  114. };
  115.  
  116.  
  117. struct Library *GadToolsBase=NULL;
  118. struct GfxBase *GfxBase=NULL;
  119. struct IntuitionBase *IntuitionBase=NULL;
  120. struct Library *LayersBase=NULL;
  121. static APTR visualinfo=NULL;
  122. static struct Menu *mMenus=NULL;
  123. static struct BitMap *bmap;
  124. static struct Window *win=NULL;
  125. static int offx=0,offy=0;
  126. static int maxx,maxy;
  127. static int borhoriz,borvert;
  128. static struct BitMap mybmap;
  129. static void *mypointer=NULL;
  130. static UWORD *mypntchip0=NULL;
  131. static UWORD *mypntchip1=NULL;
  132. static struct ColorMap *colmap=NULL;
  133. static int winsleeped=0;
  134. static struct Requester InvisibleRequester;
  135.        UBYTE PenTable[256];
  136.        unsigned char *c;
  137. static int bmx;
  138. static void *lineskip;
  139. static int WrongPen;
  140. static unsigned char PenArray0[SCRSIZE];
  141. static unsigned char PenArray1[SCRSIZE];
  142. static unsigned char *PenArrays[2]={ PenArray0,PenArray1 };
  143.  
  144. /* LORES-POINTER
  145.  */
  146. #define POINTERHEIGHT    31
  147. static UWORD pointerp0[]={ 0,384,384,3504,3504,3504,28080,28080,28080,28086,28086,28086,32758,32758,32766,32766,32764,16380,16376,16376,0,32764,0,32764,32740,32764,32740,32764,32764,32736,28672 };
  148. static UWORD pointerp1[]={ 384,960,4080,8184,8184,32760,65528,65528,65534,65535,65535,65535,65535,65535,65535,65535,65534,32766,32764,32764,65534,65534,65534,32770,32794,32770,32794,32770,32770,32768,32768 };
  149.  
  150. /* Prefs
  151.  */
  152. static int WTop,WLeft,WHeight,WWidth,Wx,Wy;
  153. static char *WPubName=NULL;
  154.  
  155. /* Protos
  156.  */
  157. static char *initgfx(void);
  158. static void freegfx(void);
  159. static int mReset(struct IntuiMessage *imsg);
  160. static int mHReset(struct IntuiMessage *imsg);
  161. static int mDebug(struct IntuiMessage *imsg);
  162. static int mPrefs(struct IntuiMessage *imsg);
  163. static int mJump(struct IntuiMessage *imsg);
  164. static int mQuit(struct IntuiMessage *imsg);
  165.  
  166. /* Menu
  167.  */
  168. static struct NewMenu mNewMenu[]={
  169.     {    NM_TITLE, (STRPTR)MSG_PROJECT, NULL, 0, NULL, NULL    },
  170.     {    NM_ITEM, (STRPTR)MSG_RESET, (STRPTR)MSG_RESET_A, 0, 0L, (APTR)mReset },
  171.     {    NM_ITEM, (STRPTR)MSG_HARDRESET, (STRPTR)MSG_HARDRESET_A, 0, 0L, (APTR)mHReset },
  172.     {    NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL    },
  173.     {    NM_ITEM, (STRPTR)MSG_DEBUG, (STRPTR)MSG_DEBUG_A, 0, 0L, (APTR)mDebug },
  174.     {    NM_ITEM, (STRPTR)MSG_PREFS, (STRPTR)MSG_PREFS_A, 0, 0L, (APTR)mPrefs },
  175.     {    NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL    },
  176.     {    NM_ITEM, (STRPTR)MSG_QUIT, (STRPTR)MSG_QUIT_A, 0, 0L, (APTR)mQuit },
  177.     {    NM_TITLE, (STRPTR)MSG_OPTIONS, NULL, 0, NULL, NULL    },
  178.     {    NM_ITEM, (STRPTR)MSG_JUMPSCR, (STRPTR)MSG_JUMPSCR_A, 0, 0L, (APTR)mJump },
  179.     {    NM_END, NULL, NULL, 0, 0L, NULL    }
  180. };
  181. static struct NewMenu sNewMenu[]={
  182.     {    NM_TITLE, (STRPTR)MSG_PROJECT, NULL, 0, NULL, NULL    },
  183.     {    NM_ITEM, (STRPTR)MSG_RESET, (STRPTR)MSG_RESET_A, 0, 0L, (APTR)mReset },
  184.     {    NM_ITEM, (STRPTR)MSG_HARDRESET, (STRPTR)MSG_HARDRESET_A, 0, 0L, (APTR)mHReset },
  185.     {    NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL    },
  186.     {    NM_ITEM, (STRPTR)MSG_DEBUG, (STRPTR)MSG_DEBUG_A, 0, 0L, (APTR)mDebug },
  187.     {    NM_ITEM, (STRPTR)MSG_PREFS, (STRPTR)MSG_PREFS_A, 0, 0L, (APTR)mPrefs },
  188.     {    NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL    },
  189.     {    NM_ITEM, (STRPTR)MSG_QUIT, (STRPTR)MSG_QUIT_A, 0, 0L, (APTR)mQuit },
  190.     {    NM_TITLE, (STRPTR)MSG_OPTIONS, NULL, 0, NULL, NULL    },
  191.     {    NM_ITEM, (STRPTR)MSG_JUMPSCR, (STRPTR)MSG_JUMPSCR_A, 0, 0L, (APTR)mJump },
  192.     {    NM_END, NULL, NULL, 0, 0L, NULL    }
  193. };
  194.  
  195.  
  196. /* Info
  197.  */
  198. char *SAVEDS minfo(void) {
  199. static char in[1024];
  200.     char *s;
  201.     c2p_OpenCatalog(cp4_windowamiga_DefaultStrings);
  202.     s=STR(MSG_INFO);
  203.     c2p_strncpy(in,s,1023);
  204.     c2p_CloseCatalog();
  205.     return(in);
  206. }
  207.  
  208. /* Handle MenuPick
  209.  */
  210. static int mReset(struct IntuiMessage *imsg) {
  211.     return(RET_RESET);
  212. } // mReset()
  213.  
  214. static int mHReset(struct IntuiMessage *imsg) {
  215.     return(RET_HRESET);
  216. } // mHReset()
  217.  
  218. static int mDebug(struct IntuiMessage *imsg) {
  219.     return(RET_DEBUG);
  220. } // mDebug()
  221.  
  222. static int mPrefs(struct IntuiMessage *imsg) {
  223.     return(RET_PREFS);
  224. } // mPrefs()
  225.  
  226. static int mQuit(struct IntuiMessage *imsg) {
  227.     return(RET_QUIT);
  228. } // mQuit()
  229.  
  230. static int mJump(struct IntuiMessage *imsg) {
  231. static char newname[MAXPUBSCREENNAME+1];
  232.     int r=RET_OK,i;
  233.     char *s;
  234.  
  235.     if(NULL!=(NextPubScreen(vec.c2p_Scr,newname))) {
  236.         if(NULL!=(s=AllocVec(MAXPUBSCREENNAME+1,MEMF_ANY))) {
  237.             freegfx();
  238.             r=RET_NEWWIN;
  239.             for(i=0;newname[i]!='\0';i++);
  240.             CopyMem(newname,s,i+1);
  241.             if(WPubName) FreeVec(WPubName);
  242.             WPubName=s;
  243.             if(NULL!=(initgfx())) {
  244.                 freegfx();
  245.                 // PANIC!!!
  246.                 Alert(AT_Recovery|AG_NoMemory|AO_Unknown);
  247.                 return(RET_ERROR);
  248.             }
  249.         }
  250.     }
  251.     return(r);
  252. } // mJump()
  253.  
  254.  
  255. static INLINE void calcwinsizes() {
  256.     borhoriz=win->BorderRight+win->BorderLeft-1;
  257.     borvert=win->BorderTop+win->BorderBottom-1;
  258.     maxx=SCRWIDTH-(win->Width-borhoriz);
  259.     maxy=SCRHEIGHT-(win->Height-borvert);
  260.     if(offx>maxx) {
  261.         ScrollLayer(0,win->RPort->Layer,-(offx-maxx),0);
  262.         offx=maxx;
  263.     }
  264.     if(offy>maxy) {
  265.         ScrollLayer(0,win->RPort->Layer,0,-(offy-maxy));
  266.         offy=maxy;
  267.     }
  268. }
  269.  
  270.  
  271. static char *initgfx(void) {
  272. static char pname[MAXPUBSCREENNAME+1];
  273.     int i,j,planes,val,mx,my;
  274.     ULONG bf=BMF_DISPLAYABLE|BMF_CLEAR|BMF_INTERLEAVED;
  275.     ULONG r,g,b,wa_top=WA_Top;
  276.  
  277.     /* Clear DeltaBuffer
  278.      */
  279.     for(i=0;i<SCRSIZE;i++) PenArray0[i]=PenArray1[i]=0xff;
  280.  
  281.     /* Get the required PubScreen
  282.      */
  283.     if(NULL==(vec.c2p_Scr=LockPubScreen(WPubName))) {
  284.         vec.c2p_Scr=LockPubScreen(NULL);
  285.         GetDefaultPubScreen(pname);
  286.         if(WPubName) FreeVec(WPubName);
  287.         for(i=0;pname[i]!='\0';i++);
  288.         if(NULL==(WPubName=AllocVec(i+2,MEMF_ANY))) return(C2P_NOMEM);
  289.         CopyMem(pname,WPubName,i+1);
  290.     }
  291.  
  292.     /* ScreenToFront
  293.      */
  294.     ScreenToFront(vec.c2p_Scr);
  295.  
  296.     /* Get Screen Attribs
  297.      */
  298.     planes=vec.c2p_Scr->BitMap.Depth;
  299.     if(!(visualinfo=GetVisualInfo(vec.c2p_Scr,TAG_DONE))) return(STR(MSG_ERRVISUALINFO));
  300.  
  301.     /* Allocate bitmaps
  302.      */
  303.     if(NULL==(bmap=AllocBitMap(SCRWIDTH,SCRHEIGHT,planes,bf,NULL))) return(C2P_NOMEM);
  304.  
  305.     /* SetUp Menu
  306.      */
  307.     for(i=0;sNewMenu[i].nm_Type!=NM_END;i++) {
  308.         mNewMenu[i].nm_Label=sNewMenu[i].nm_Label;
  309.         mNewMenu[i].nm_CommKey=sNewMenu[i].nm_CommKey;
  310.     }
  311.     for(i=0;mNewMenu[i].nm_Type!=NM_END;i++) {
  312.         if(mNewMenu[i].nm_Label!=NM_BARLABEL) mNewMenu[i].nm_Label=STR((long)mNewMenu[i].nm_Label);
  313.         if(mNewMenu[i].nm_CommKey!=NULL) mNewMenu[i].nm_CommKey=STR((long)mNewMenu[i].nm_CommKey);
  314.     }
  315.     if(!(mMenus=CreateMenus(mNewMenu,GTMN_FrontPen,0L,TAG_DONE,0L))) return(STR(MSG_ERRCREATEMENU));
  316.     LayoutMenus(mMenus,visualinfo,GTMN_TextAttr,(ULONG)vec.c2p_Scr->Font,GTMN_NewLookMenus,TRUE,TAG_DONE,0L);
  317.  
  318.     /* Open window
  319.      */
  320.     if(WTop==-1) { wa_top=TAG_IGNORE; WTop=0; }
  321.     if((win=(struct Window *)OpenWindowTags(NULL,
  322.                 WA_Left, WLeft,
  323.                 wa_top, WTop,
  324.                 WA_Width, WWidth,
  325.                 WA_Height, WHeight,
  326.                 WA_Title, (ULONG)"WindowAmiga",
  327.                 WA_Flags,    WFLG_SIZEGADGET|
  328.                             WFLG_SIZEBBOTTOM|
  329.                             WFLG_DRAGBAR|
  330.                             WFLG_DEPTHGADGET|
  331.                             WFLG_CLOSEGADGET|
  332.                             WFLG_SUPER_BITMAP|
  333.                             WFLG_GIMMEZEROZERO|
  334.                             WFLG_ACTIVATE,
  335.                 WA_SuperBitMap, (ULONG)bmap,
  336.                 WA_AutoAdjust, TRUE,
  337.                 WA_RptQueue, 25,
  338.                 WA_IDCMP,     IDCMP_MOUSEMOVE|
  339.                             IDCMP_MENUPICK|
  340.                             IDCMP_CLOSEWINDOW|
  341.                             IDCMP_NEWSIZE|
  342.                             IDCMP_MOUSEBUTTONS,
  343.                 WA_PubScreen, (ULONG)vec.c2p_Scr,
  344.                 WA_PubScreenFallBack, TRUE,
  345.                 WA_NewLookMenus, TRUE,
  346.                 TAG_DONE,0L ))==NULL)
  347.         return(STR(MSG_ERROPENWIN));
  348.     SetMenuStrip(win,mMenus);
  349.     vec.c2p_Win=win;
  350.     winsleeped=0;
  351.     offx=offy=0;
  352.     calcwinsizes();
  353.     WindowLimits(win,borhoriz+80,borvert+20,SCRWIDTH+borhoriz,borvert+SCRHEIGHT);
  354.     offx+=Wx;        offy+=Wy;
  355.     mx=Wx;            my=Wy;
  356.     if(offx<0)        { mx-=offx; offx=0; }
  357.     if(offx>maxx)    { mx-=offx-maxx; offx=maxx; }
  358.     if(offy<0)        { my-=offy; offy=0; }
  359.     if(offy>maxy)    { my-=offy-maxy; offy=maxy; }
  360.     ScrollLayer(0,win->RPort->Layer,mx,my);
  361.  
  362.     /* Allocate bitmaps
  363.      */
  364.     bmx=GetBitMapAttr(bmap,BMA_WIDTH)/8;
  365.     if(planes>1) bf=BMF_DISPLAYABLE|BMF_INTERLEAVED|BMF_STANDARD;
  366.     else bf=BMF_DISPLAYABLE|BMF_STANDARD;
  367.     if(bf!=GetBitMapAttr(bmap,BMA_FLAGS)) return(STR(MSG_ERRBITMAPATTR));
  368.  
  369.     if(0!=c2pinit(bmx,lineskip,planes)) return(STR(MSG_ERRBITPNUM));
  370.  
  371.     /* SetUp PenTable
  372.      */
  373.     if(NULL==(colmap=vec.c2p_Scr->ViewPort.ColorMap)) return(STR(MSG_ERRFINDCOLMAP));
  374.     for(i=0;i<256;i++) {
  375.         j=ColorPriority[i]*3;
  376.         r=Palette[j];
  377.         g=Palette[j+1];
  378.         b=Palette[j+2];
  379.         if(-1==(val=ObtainBestPen(colmap,r,g,b,OBP_Precision,PRECISION_GUI,TAG_DONE))) {
  380.             WrongPen=i;
  381.             return(STR(MSG_ERROBTPENS));
  382.         }
  383.         PenTable[ColorPriority[i]]=(UBYTE)val;
  384.     }
  385.     WrongPen=256;
  386.     return(NULL);
  387. } // initgfx()
  388.  
  389.  
  390. static void freegfx(void) {
  391.     int i;
  392.     mawake();
  393.     if(GfxBase) {
  394.         WaitTOF();
  395.         if(colmap) for(i=0;i<WrongPen;i++) ReleasePen(colmap,(ULONG)PenTable[i]);
  396.     }
  397.     if(win) {
  398.         WTop=win->TopEdge;
  399.         WLeft=win->LeftEdge;
  400.         WHeight=win->Height;
  401.         WWidth=win->Width;
  402.         vec.c2p_AddOptionInt("WINTOP",WTop);
  403.         vec.c2p_AddOptionInt("WINLEFT",WLeft);
  404.         vec.c2p_AddOptionInt("WINHEIGHT",WHeight);
  405.         vec.c2p_AddOptionInt("WINWIDTH",WWidth);
  406.         Wx=offx;
  407.         Wy=offy;
  408.         vec.c2p_AddOptionInt("OFFX",Wx);
  409.         vec.c2p_AddOptionInt("OFFY",Wy);
  410.         ClearMenuStrip(win);
  411.         CloseWindow(win);
  412.         win=NULL;
  413.     }
  414.     vec.c2p_Win=NULL;
  415.     if(mMenus) { FreeMenus(mMenus); mMenus=NULL; }
  416.     if(visualinfo) { FreeVisualInfo(visualinfo); visualinfo=NULL; }
  417.     if(vec.c2p_Scr) {
  418.         vec.c2p_AddOptionStr("PUBSCREEN",WPubName);
  419.         UnlockPubScreen(NULL,vec.c2p_Scr);
  420.         vec.c2p_Scr=NULL;
  421.     }
  422.     if(bmap) { FreeBitMap(bmap); bmap=NULL; }
  423. } // freegfx()
  424.  
  425.  
  426. char *SAVEDS minit(ULONG scrmode, ULONG overscan, unsigned char *linedeltatab) {
  427.     ULONG res;
  428.     int i;
  429.     char *s;
  430.  
  431.  
  432.     c2p_OpenCatalog(cp4_windowamiga_DefaultStrings);
  433.  
  434.     WrongPen=0;
  435.     lineskip=linedeltatab;
  436.  
  437.     if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",39))) return(STR(MSG_ERRGRAPHICS));
  438.     if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",39))) return(STR(MSG_ERRINTUITION));
  439.     if(!(LayersBase=OpenLibrary("layers.library",33))) return(STR(MSG_ERRLAYERS));
  440.     if(!(GadToolsBase=OpenLibrary("gadtools.library",37))) return(STR(MSG_ERRGADTOOLS));
  441.  
  442.     /* Set up pointer
  443.      */
  444.     if(NULL==(mypntchip0=AllocVec((POINTERHEIGHT+1)*2,MEMF_CHIP))) return(C2P_NOMEM);
  445.     if(NULL==(mypntchip1=AllocVec((POINTERHEIGHT+1)*2,MEMF_CHIP))) return(C2P_NOMEM);
  446.     CopyMem(pointerp0,mypntchip0,2*POINTERHEIGHT);
  447.     CopyMem(pointerp1,mypntchip1,2*POINTERHEIGHT);
  448.     InitBitMap(&mybmap,2,16,POINTERHEIGHT);
  449.     mybmap.Planes[0]=(PLANEPTR)mypntchip0;
  450.     mybmap.Planes[1]=(PLANEPTR)mypntchip1;
  451.     res=POINTERYRESN_DEFAULT;
  452.     if(((GfxBase->ChipRevBits0&GFXF_HR_AGNUS)!=0)&&((GfxBase->ChipRevBits0&GFXF_HR_DENISE)!=0)) res=POINTERXRESN_SCREENRES;
  453.     mypointer=NewObject(NULL,"pointerclass",
  454.         POINTERA_BitMap, (ULONG)&mybmap,
  455.         POINTERA_XOffset, -6,
  456.         POINTERA_WordWidth, 1,
  457.         POINTERA_XResolution, res,
  458.         POINTERA_YResolution, res,
  459.         TAG_DONE );
  460.     if(mypointer==NULL) return(STR(MSG_ERRPOINTER));
  461.  
  462.     /* Get Options
  463.      */
  464.     Wx=vec.c2p_GetOptionInt("OFFX",0);
  465.     Wy=vec.c2p_GetOptionInt("OFFY",0);
  466.     WTop=vec.c2p_GetOptionInt("WINTOP",-1);
  467.     WLeft=vec.c2p_GetOptionInt("WINLEFT",0);
  468.     WHeight=vec.c2p_GetOptionInt("WINHEIGHT",303);
  469.     WWidth=vec.c2p_GetOptionInt("WINWIDTH",359);
  470.     s=vec.c2p_GetOptionStr("PUBSCREEN","Workbench");
  471.     for(i=0;s[i]!='\0';i++);
  472.     if(NULL==(WPubName=AllocVec(i+2,MEMF_ANY))) return(C2P_NOMEM);
  473.     CopyMem(s,WPubName,i+1);
  474.  
  475.     return(initgfx());
  476. } // minit
  477.  
  478.  
  479. void SAVEDS mfree(void) {
  480.     freegfx();
  481.     if(mypntchip0) { FreeVec(mypntchip0); mypntchip0=NULL; }
  482.     if(mypntchip1) { FreeVec(mypntchip1); mypntchip1=NULL; }
  483.     if(mypointer) { DisposeObject(mypointer); mypointer=NULL; }
  484.     if(WPubName) { FreeVec(WPubName); WPubName=NULL; }
  485.     if(GfxBase) CloseLibrary((struct Library *)GfxBase);
  486.     if(IntuitionBase) { CloseLibrary((struct Library *)IntuitionBase); IntuitionBase=NULL; }
  487.     if(LayersBase) CloseLibrary(LayersBase);
  488.     if(GadToolsBase) { CloseLibrary(GadToolsBase); GadToolsBase=NULL; }
  489.     c2p_CloseCatalog();
  490. } // mfree
  491.  
  492.  
  493. static int handleidcmp() {
  494.     struct IntuiMessage *imsg;
  495.     struct MenuItem *n;
  496.     int ret=RET_OK,move=0,lastx=0,lasty=0;
  497.     int (*func)(struct IntuiMessage *);
  498.  
  499.     while((imsg=(struct IntuiMessage *)RemHead(&vec.c2p_MsgList))) {
  500.         switch(imsg->Class) {
  501.             case IDCMP_CLOSEWINDOW :
  502.                 ret=RET_QUIT;
  503.                 break;
  504.             case IDCMP_NEWSIZE :
  505.                 calcwinsizes();
  506.                 break;
  507.             case IDCMP_MENUPICK :
  508.                 while(imsg->Code!=MENUNULL) {
  509.                     n=ItemAddress(mMenus,imsg->Code);
  510.                     func=(void *)(GTMENUITEM_USERDATA(n));
  511.                     ret=func(imsg);
  512.                     if(ret==RET_NEWWIN||ret==RET_ERROR) return(ret);
  513.                     imsg->Code=n->NextSelect;
  514.                 }
  515.                 break;
  516.             case IDCMP_MOUSEBUTTONS :
  517.                 if(imsg->Code==SELECTDOWN) {
  518.                     move=1;
  519.                     lastx=imsg->MouseX;
  520.                     lasty=imsg->MouseY;
  521.                 } else move=0;
  522.                 break;
  523.         }
  524.     }
  525.  
  526.     /* Handle Drag Window
  527.      */
  528.     if(move!=0) {
  529.         int mx,my,class,t1,t2;
  530.  
  531.         ReportMouse(TRUE,win);
  532.         SetWindowPointer(win,WA_Pointer,(ULONG)mypointer,TAG_DONE);
  533.         while(move!=0) {
  534.             WaitPort(win->UserPort);
  535.             imsg=(struct IntuiMessage *)GetMsg(win->UserPort);
  536.             mx=imsg->MouseX;
  537.             my=imsg->MouseY;
  538.             class=imsg->Class;
  539.             ReplyMsg((struct Message *)imsg);
  540.             switch(class) {
  541.                 case IDCMP_MOUSEBUTTONS :
  542.                     move=0;
  543.                     break;
  544.                 case IDCMP_MOUSEMOVE :
  545.                     offx+=lastx-mx;    offy+=lasty-my;
  546.                     t1=mx;            t2=my;
  547.                     mx=lastx-mx;    my=lasty-my;
  548.                     lastx=t1;        lasty=t2;
  549.                     if(offx<0)        { mx-=offx; offx=0; }
  550.                     if(offx>maxx)    { mx-=offx-maxx; offx=maxx; }
  551.                     if(offy<0)        { my-=offy; offy=0; }
  552.                     if(offy>maxy)    { my-=offy-maxy; offy=maxy; }
  553.                     ScrollLayer(0,win->RPort->Layer,mx,my);
  554.                     break;
  555.             }
  556.         }
  557.         SetWindowPointer(win,TAG_DONE);
  558.         ReportMouse(FALSE,win);
  559.     }
  560.     return(ret);
  561. } // handleidcmp()
  562.  
  563.  
  564. int SAVEDS mdo(unsigned char *chunky,unsigned char *delta,int numscreen) {
  565. static int cnt=0;
  566.     int ret=0;
  567.  
  568.     /* handle input
  569.      */
  570.     ret=handleidcmp();
  571.  
  572.     /* Convert chunky into PenArray (in asm)
  573.      */    
  574.     c=chunky;
  575.  
  576.     if(ret!=RET_NEWWIN||ret!=RET_ERROR) {
  577.         /* Do the c2p
  578.          */
  579.         c2pdelta(PenArrays[cnt],PenArrays[cnt^1],bmap->Planes[0],lineskip,bmx);
  580.  
  581.         /* Copy into the window
  582.          */
  583.         LockLayerRom(win->RPort->Layer);
  584.         CopySBitMap(win->RPort->Layer);
  585.         UnlockLayerRom(win->RPort->Layer);
  586.  
  587.         /* Another Array
  588.          */
  589.         cnt^=1;
  590.     }
  591.     return(ret);
  592. } // do
  593.  
  594.  
  595. int SAVEDS mdofull(unsigned char *chunky,int numscreen) {
  596.     int ret=0,i;
  597.     unsigned char *p,*c;
  598.  
  599.     /* handle input
  600.      */
  601.     ret=handleidcmp();
  602.  
  603.     /* Convert chunky into PenArray
  604.      */    
  605.     i=SCRSIZE;
  606.     c=chunky;
  607.     p=PenArray0;
  608.     do { *p++=PenTable[*c++]; } while(--i);
  609.  
  610.     if(ret!=RET_NEWWIN||ret!=RET_ERROR) {
  611.         /* Do the c2p
  612.          */
  613.         c2pfull(PenArray0,bmap->Planes[0],bmx);
  614.  
  615.         /* Copy into the window
  616.          */
  617.         LockLayerRom(win->RPort->Layer);
  618.         CopySBitMap(win->RPort->Layer);
  619.         UnlockLayerRom(win->RPort->Layer);
  620.     }
  621.  
  622.     return(ret);
  623. } // dofull
  624.  
  625.  
  626. int SAVEDS mdont(void) {
  627.     int ret;
  628.  
  629.     /* handle input
  630.      */
  631.     ret=handleidcmp();
  632.     return(ret);
  633. } // dont
  634.  
  635.  
  636. void SAVEDS msleep(void) {
  637.     if(win) {
  638.         InitRequester(&InvisibleRequester);
  639.         Request(&InvisibleRequester,win);
  640.         SetWindowPointer(win,WA_BusyPointer,TRUE,TAG_DONE);
  641.         winsleeped=1;
  642.     }
  643. }
  644.  
  645.  
  646. void SAVEDS mawake(void) {
  647.     if(winsleeped) {
  648.         if(win) {
  649.             EndRequest(&InvisibleRequester,win);
  650.             SetWindowPointerA(win,NULL);
  651.             winsleeped=0;
  652.         }
  653.     }
  654. }
  655.